var CustomerMemberTable = {
    id: "CustomerMemberTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

CustomerMemberTable.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle',},
        {title: 'openId', field: 'openId', visible: false, align: 'center', valign: 'middle',},
        {title: '', field: 'customerSexHead ', visible: false, align: 'center', valign: 'middle'},
        {title: 'account', field: 'account', visible: false, align: 'center', valign: 'middle',},
        {title: '姓名', field: 'name', valign: 'middle', align: 'center', sortable: true, width: 120,
            formatter: function (value, row, index) {
                return "<a href='javascript:;' style='color: green;display: flex;align-items: center;'><img src='" + row.customerSexHead + "' alt='' width='40px'><span class='portraitHeadName'>" + value + "</span></a>"
            }
        },
        {title: '年龄', field: 'age', align: 'center', valign: 'middle', sortable: true, width: 70,},
        {title: '性别', field: 'sex', align: 'center', valign: 'middle', sortable: true, width: 70,},
        {title: '手机号码', field: 'phone', align: 'center', valign: 'middle', sortable: true, width: 110,},
        {title: '会员卡号', field: 'membersNum', align: 'center', valign: 'middle', sortable: true, width: 110,},
        {title: '会员等级', field: 'vipLevelName', align: 'center', valign: 'middle', sortable: true, width: 110,},
        {title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', sortable: true, width: 110,},
        {title: '门诊', field: 'simplename', align: 'center', valign: 'middle', sortable: true, width: 80,},
        {title: '注册时间', field: 'cTime', align: 'center', valign: 'middle', sortable: true, width: 140,},
        {title: '扫码时间', field: 'updateTime', align: 'center', valign: 'middle', sortable: true, width: 140,}
    ];
    return columns;
};

CustomerMemberTable.search = function () {
    CustomerMemberTable.table.refresh({query: CustomerMemberTable.formParams()});
};

CustomerMemberTable.close = function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
};

CustomerMemberTable.formParams = function () { // 市场预约表单查询提交参数
    var queryData = {};
    queryData['outpatientName'] = $("#outpatientName", parent.document).val();
    queryData['phone'] = $("#searchPhone").val();
    queryData['startCTime'] = $("#startCTime").val();
    queryData['endCTime'] = $("#endCTime").val();
    queryData['startUpdateTime'] = $("#startUpdateTime").val();
    queryData['endUpdateTime'] = $("#endUpdateTime").val();
    return queryData;
};

CustomerMemberTable.searchPhone = function () {
    CustomerMemberTable.table.refresh({
        query: CustomerMemberTable.formParams()
    });
};

var parseParam = function (param) {
    var paramStr = "";
    $.each(param, function (i) {
        paramStr += '&' + getSingleData(param, i);
    });
    return paramStr.substr(1);
};
var getSingleData = function (param, key) {
    return key + "=" + param[key];
};
CustomerMemberTable.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CustomerMemberTable.seItem = selected[0];
        return true;
    }
};
CustomerMemberTable.getUserList = function () {
    $.ajax({
        url: Feng.ctxPath + "/wxWeixin/getWxUserInfoList/",
        type: "GET",
        success: function (data) {
            console.log(data)
        },
        error: function (data) {
            alert('没有权限，请联系系统管理员!');
            parent.layer.close(windowNameIndex)
        }
    })
};

CustomerMemberTable.resetSearch = function () { // 重置
    $("#marketInputPublic", parent.document).val("");
    $("#outpatientName").selectpicker('deselectAll');
    $("#startCTime").val("");
    $("#endCTime").val("");
    $("#startUpdateTime").val("");
    $("#endUpdateTime").val("");
    $("#searchPhone").val("");
    CustomerMemberTable.search();
};

$("#marketSearchAll", parent.document).click(function () { // 主页搜索
    CustomerMemberTable.search();
});

var scollPostion = 0;
CustomerMemberTable.getScrollPosition = function (){ // 获取表格滚动到什么地方
    scollPostion = $('#CustomerMemberTable').bootstrapTable('getScrollPosition');
};

CustomerMemberTable.scrollTo = function (){ // 指定表格滚动到什么地方
    $("#CustomerMemberTable").on('load-success.bs.table',function(data){
        $('#CustomerMemberTable').bootstrapTable('scrollTo', scollPostion);
    });
};
CustomerMemberTable.today = function () { // 点击上面状态筛选表格
    $("#startUpdateTime").val(setDateTime(new Date(),0) + " " + "00:00:00");
    $("#endUpdateTime").val(setDateTime(new Date(),0) + " " + "23:59:59");
    CustomerMemberTable.search();
};

function phonePrivileges(){   //隐藏手机号
    var phonePrivileges=parent.$("#phonePrivileges").val();
    if(phonePrivileges == 2){
        $('#CustomerMemberTable').bootstrapTable('hideColumn', 'phone');
    }
}

$(function () {
    var defaultColunms = CustomerMemberTable.initColumn();
    var table = new BSTable(CustomerMemberTable.id, "/customer/customerMemberList", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(CustomerMemberTable.formParams());
    CustomerMemberTable.table = table.init();
    CustomerMemberTable.today();
    menuNameHideColumn($("#menuName").val(),'CustomerMemberTable');
    $(document).on('click','#laydate_clear,#laydate_today,#laydate_ok',function () {CustomerMemberTable.search();});
    checkDate = function () {CustomerMemberTable.search();};
    callbackTable = function () {CustomerMemberTable.search();};
    phonePrivileges();
});